package com.neusoft.EYSystem.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.EYSystem.po.CaretakerTodayCount;
import com.neusoft.EYSystem.po.NursingRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CaretakerTodayCountDAO extends BaseMapper<NursingRecord> {
    @Select("SELECT u.username AS name, " +
            "IFNULL(SUM(nr.quantity), 0) AS count " +
            "FROM user u " +
            "LEFT JOIN nursing_record nr ON u.user_id = nr.caretaker_id " +
            "AND DATE(nr.nursing_time) = CURDATE() " +
            "AND nr.is_visible = 1 " +
            "WHERE u.role = 'caretaker' " +
            "GROUP BY u.user_id " +
            "ORDER BY count DESC")
    List<CaretakerTodayCount> getCaretakerTodayCount();
}
